home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Windows 95 with MFC
/
Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso
/
NT
/
CODE
/
CHAP08
/
PAINT4
/
PAINT4VIEW.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-05
|
2KB
|
101 lines
//***********************************************************************
//
// Paint4View.cpp
//
//***********************************************************************
#include <afxwin.h>
#include "Resource.h"
#include "CLine.h"
#include "Paint4Doc.h"
#include "Paint4View.h"
IMPLEMENT_DYNCREATE (CPaintView, CScrollView)
BEGIN_MESSAGE_MAP (CPaintView, CScrollView)
ON_WM_LBUTTONDOWN ()
ON_WM_MOUSEMOVE ()
ON_WM_LBUTTONUP ()
ON_WM_CONTEXTMENU ()
END_MESSAGE_MAP ()
void CPaintView::OnInitialUpdate ()
{
SetScrollSizes (MM_TEXT, CSize (2048, 2048));
CScrollView::OnInitialUpdate ();
}
void CPaintView::OnDraw (CDC* pDC)
{
CPaintDoc* pDoc = GetDocument ();
int nCount = pDoc->GetLineCount ();
if (nCount) {
for (int i=0; i<nCount; i++)
pDoc->GetLine (i)->Draw (pDC);
}
}
void CPaintView::OnLButtonDown (UINT nFlags, CPoint point)
{
CClientDC dc (this);
OnPrepareDC (&dc);
dc.DPtoLP (&point);
m_ptFrom = point;
m_ptTo = point;
SetCapture ();
}
void CPaintView::OnMouseMove (UINT nFlags, CPoint point)
{
if (GetCapture () == this) {
CClientDC dc (this);
OnPrepareDC (&dc);
dc.DPtoLP (&point);
InvertLine (&dc, m_ptFrom, m_ptTo);
InvertLine (&dc, m_ptFrom, point);
m_ptTo = point;
}
}
void CPaintView::OnLButtonUp (UINT nFlags, CPoint point)
{
if (GetCapture () == this) {
ReleaseCapture ();
CClientDC dc (this);
OnPrepareDC (&dc);
dc.DPtoLP (&point);
InvertLine (&dc, m_ptFrom, m_ptTo);
CLine* pLine = GetDocument ()->AddLine (m_ptFrom, point);
if (pLine != NULL)
pLine->Draw (&dc);
}
}
void CPaintView::InvertLine (CDC* pDC, CPoint ptFrom, CPoint ptTo)
{
int nOldMode = pDC->SetROP2 (R2_NOT);
pDC->MoveTo (ptFrom);
pDC->LineTo (ptTo);
pDC->SetROP2 (nOldMode);
}
void CPaintView::OnContextMenu (CWnd* pWnd, CPoint point)
{
CMenu menu;
menu.LoadMenu (IDR_CONTEXTMENU);
CMenu* pContextMenu = menu.GetSubMenu (0);
for (int i=0; i<8; i++)
pContextMenu->ModifyMenu (ID_COLOR_BLACK + i,
MF_BYCOMMAND | MF_OWNERDRAW, ID_COLOR_BLACK + i);
pContextMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_LEFTBUTTON |
TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd ());
}